//
//  BasicTableViewController.swift
//  WeiBo
//
//  Created by 小小罗 on 15/11/4.
//  Copyright © 2015年 RealMadrid. All rights reserved.
//

import UIKit


//封装一个基类继承于UITableViewController  让其他控制器都继承与这个基类
class BasicTableViewController: UITableViewController {
    
        
    //判断用户是否登录
    private var userLogon = UserAccountViewModel.sharedUserAccount.userLogon
    
    //访客视图
    var basicView: BasicView?
    
    override func loadView() {
        userLogon ? super.loadView() : setupBasicView()
    }
    
    
    //设置访客视图
    private func setupBasicView() {
        
        basicView = BasicView()
        view = basicView
        
        //为注册按钮和登陆按钮添加监听方法
        basicView?.registerButton.addTarget(self, action: "basicViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        basicView?.loginButton.addTarget(self, action: "basicViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        
        // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
    
    }
    

    
}


extension BasicTableViewController {
    
    func basicViewDidRegister() {
        print("注册")
    }
    
    func basicViewDidLogin() {
        
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
         //modal控制器
        presentViewController(nav, animated: true, completion: nil)
        
        
    }
}



